<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActiveResource::Errors</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActiveResource::Errors</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/activeresource/lib/active_resource/validations_rb.html">
                vendor/rails/activeresource/lib/active_resource/validations.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Active Resource validation is reported to and from this object, which is
used by <a href="Base.html#M001267">Base#save</a> to determine whether the
object in a valid state to be saved. See usage example in <a
href="Validations.html">Validations</a>.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M001216">[]</a>&nbsp;&nbsp;
      <a href="#M001213">add</a>&nbsp;&nbsp;
      <a href="#M001212">add_to_base</a>&nbsp;&nbsp;
      <a href="#M001221">clear</a>&nbsp;&nbsp;
      <a href="#M001223">count</a>&nbsp;&nbsp;
      <a href="#M001218">each</a>&nbsp;&nbsp;
      <a href="#M001219">each_full</a>&nbsp;&nbsp;
      <a href="#M001225">from_xml</a>&nbsp;&nbsp;
      <a href="#M001220">full_messages</a>&nbsp;&nbsp;
      <a href="#M001214">invalid?</a>&nbsp;&nbsp;
      <a href="#M001224">length</a>&nbsp;&nbsp;
      <a href="#M001215">on</a>&nbsp;&nbsp;
      <a href="#M001217">on_base</a>&nbsp;&nbsp;
      <a href="#M001222">size</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="../Enumerable.html">Enumerable</a></span>
      </div>
    </div>

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">errors</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M001216" class="method-detail">
        <a name="M001216"></a>

        <div class="method-heading">
          <span class="method-name">[]</span><span class="method-args">(attribute)</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="Errors.html#M001215">on</a>
</p>
        </div>
      </div>

      <div id="method-M001213" class="method-detail">
        <a name="M001213"></a>

        <div class="method-heading">
          <a href="#M001213" class="method-signature">
          <span class="method-name">add</span><span class="method-args">(attribute, msg)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Adds an error to an Active Resource object&#8216;s attribute (named for the
<tt>attribute</tt> parameter) with the error message in <tt>msg</tt>.
</p>
<h4>Examples</h4>
<pre>
  my_resource = Node.find(1)
  my_resource.errors.add('name', 'can not be &quot;base&quot;') if my_resource.name == 'base'
  my_resource.errors.on('name')
  # =&gt; 'can not be &quot;base&quot;!'

  my_resource.errors.add('desc', 'can not be blank') if my_resource.desc == ''
  my_resource.valid?
  # =&gt; false
  my_resource.errors.on('desc')
  # =&gt; 'can not be blank!'
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001213-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001213-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/validations.rb, line 50</span>
50:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add</span>(<span class="ruby-identifier">attribute</span>, <span class="ruby-identifier">msg</span>)
51:       <span class="ruby-ivar">@errors</span>[<span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">to_s</span>] = [] <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@errors</span>[<span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">to_s</span>].<span class="ruby-identifier">nil?</span>
52:       <span class="ruby-ivar">@errors</span>[<span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">to_s</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">msg</span>
53:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001212" class="method-detail">
        <a name="M001212"></a>

        <div class="method-heading">
          <a href="#M001212" class="method-signature">
          <span class="method-name">add_to_base</span><span class="method-args">(msg)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Add an error to the base Active Resource object rather than an attribute.
</p>
<h4>Examples</h4>
<pre>
  my_folder = Folder.find(1)
  my_folder.errors.add_to_base(&quot;You can't edit an existing folder&quot;)
  my_folder.errors.on_base
  # =&gt; &quot;You can't edit an existing folder&quot;

  my_folder.errors.add_to_base(&quot;This folder has been tagged as frozen&quot;)
  my_folder.valid?
  # =&gt; false
  my_folder.errors.on_base
  # =&gt; [&quot;You can't edit an existing folder&quot;, &quot;This folder has been tagged as frozen&quot;]
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001212-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001212-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/validations.rb, line 31</span>
31:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_to_base</span>(<span class="ruby-identifier">msg</span>)
32:       <span class="ruby-identifier">add</span>(<span class="ruby-identifier">:base</span>, <span class="ruby-identifier">msg</span>)
33:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001221" class="method-detail">
        <a name="M001221"></a>

        <div class="method-heading">
          <a href="#M001221" class="method-signature">
          <span class="method-name">clear</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001221-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001221-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/validations.rb, line 178</span>
178:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear</span>
179:       <span class="ruby-ivar">@errors</span> = {}
180:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001223" class="method-detail">
        <a name="M001223"></a>

        <div class="method-heading">
          <span class="method-name">count</span><span class="method-args">()</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="Errors.html#M001222">size</a>
</p>
        </div>
      </div>

      <div id="method-M001218" class="method-detail">
        <a name="M001218"></a>

        <div class="method-heading">
          <a href="#M001218" class="method-signature">
          <span class="method-name">each</span><span class="method-args">() {|attr, msg| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Yields <a href="Errors.html#M001218">each</a> attribute and associated
message per error added.
</p>
<h4>Examples</h4>
<pre>
  my_person = Person.new(params[:person])

  my_person.errors.add('login', 'can not be empty') if my_person.login == ''
  my_person.errors.add('password', 'can not be empty') if my_person.password == ''
  messages = ''
  my_person.errors.each {|attr, msg| messages += attr.humanize + &quot; &quot; + msg + &quot;&lt;br /&gt;&quot;}
  messages
  # =&gt; &quot;Login can not be empty&lt;br /&gt;Password can not be empty&lt;br /&gt;&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001218-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001218-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/validations.rb, line 128</span>
128:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each</span>
129:       <span class="ruby-ivar">@errors</span>.<span class="ruby-identifier">each_key</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">attr</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@errors</span>[<span class="ruby-identifier">attr</span>].<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">msg</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">attr</span>, <span class="ruby-identifier">msg</span> } }
130:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001219" class="method-detail">
        <a name="M001219"></a>

        <div class="method-heading">
          <a href="#M001219" class="method-signature">
          <span class="method-name">each_full</span><span class="method-args">() {|msg| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Yields <a href="Errors.html#M001218">each</a> full error message added. So
Person.errors.<a href="Errors.html#M001213">add</a>(&quot;first_name&quot;,
&quot;can&#8216;t be empty&quot;) will be returned through iteration as
&quot;First name can&#8216;t be empty&quot;.
</p>
<h4>Examples</h4>
<pre>
  my_person = Person.new(params[:person])

  my_person.errors.add('login', 'can not be empty') if my_person.login == ''
  my_person.errors.add('password', 'can not be empty') if my_person.password == ''
  messages = ''
  my_person.errors.each_full {|msg| messages += msg + &quot;&lt;br/&gt;&quot;}
  messages
  # =&gt; &quot;Login can not be empty&lt;br /&gt;Password can not be empty&lt;br /&gt;&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001219-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001219-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/validations.rb, line 145</span>
145:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each_full</span>
146:       <span class="ruby-identifier">full_messages</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">msg</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">msg</span> }
147:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001225" class="method-detail">
        <a name="M001225"></a>

        <div class="method-heading">
          <a href="#M001225" class="method-signature">
          <span class="method-name">from_xml</span><span class="method-args">(xml)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Grabs errors from the XML response.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001225-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001225-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/validations.rb, line 203</span>
203:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">from_xml</span>(<span class="ruby-identifier">xml</span>)
204:       <span class="ruby-identifier">clear</span>
205:       <span class="ruby-identifier">humanized_attributes</span> = <span class="ruby-ivar">@base</span>.<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">inject</span>({}) { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span>, <span class="ruby-identifier">attr_name</span><span class="ruby-operator">|</span> <span class="ruby-identifier">h</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">attr_name</span>.<span class="ruby-identifier">humanize</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">attr_name</span>) }
206:       <span class="ruby-identifier">messages</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">from_xml</span>(<span class="ruby-identifier">xml</span>)[<span class="ruby-value str">'errors'</span>][<span class="ruby-value str">'error'</span>] <span class="ruby-keyword kw">rescue</span> []
207:       <span class="ruby-identifier">messages</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">message</span><span class="ruby-operator">|</span>
208:         <span class="ruby-identifier">attr_message</span> = <span class="ruby-identifier">humanized_attributes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">detect</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr_name</span><span class="ruby-operator">|</span>
209:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">message</span>[<span class="ruby-value">0</span>, <span class="ruby-identifier">attr_name</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>] <span class="ruby-operator">==</span> <span class="ruby-node">&quot;#{attr_name} &quot;</span>
210:             <span class="ruby-identifier">add</span> <span class="ruby-identifier">humanized_attributes</span>[<span class="ruby-identifier">attr_name</span>], <span class="ruby-identifier">message</span>[(<span class="ruby-identifier">attr_name</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>)<span class="ruby-operator">..</span><span class="ruby-value">-1</span>]
211:           <span class="ruby-keyword kw">end</span>
212:         <span class="ruby-keyword kw">end</span>
213:         
214:         <span class="ruby-identifier">add_to_base</span> <span class="ruby-identifier">message</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">attr_message</span>.<span class="ruby-identifier">nil?</span>
215:       <span class="ruby-keyword kw">end</span>
216:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001220" class="method-detail">
        <a name="M001220"></a>

        <div class="method-heading">
          <a href="#M001220" class="method-signature">
          <span class="method-name">full_messages</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns all the full error messages in an array.
</p>
<h4>Examples</h4>
<pre>
  my_person = Person.new(params[:person])

  my_person.errors.add('login', 'can not be empty') if my_person.login == ''
  my_person.errors.add('password', 'can not be empty') if my_person.password == ''
  messages = ''
  my_person.errors.full_messages.each {|msg| messages += msg + &quot;&lt;br/&gt;&quot;}
  messages
  # =&gt; &quot;Login can not be empty&lt;br /&gt;Password can not be empty&lt;br /&gt;&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001220-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001220-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/validations.rb, line 161</span>
161:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">full_messages</span>
162:       <span class="ruby-identifier">full_messages</span> = []
163: 
164:       <span class="ruby-ivar">@errors</span>.<span class="ruby-identifier">each_key</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr</span><span class="ruby-operator">|</span>
165:         <span class="ruby-ivar">@errors</span>[<span class="ruby-identifier">attr</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">msg</span><span class="ruby-operator">|</span>
166:           <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">msg</span>.<span class="ruby-identifier">nil?</span>
167: 
168:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">attr</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;base&quot;</span>
169:             <span class="ruby-identifier">full_messages</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">msg</span>
170:           <span class="ruby-keyword kw">else</span>
171:             <span class="ruby-identifier">full_messages</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-identifier">attr</span>.<span class="ruby-identifier">humanize</span>, <span class="ruby-identifier">msg</span>].<span class="ruby-identifier">join</span>(<span class="ruby-value str">' '</span>)
172:           <span class="ruby-keyword kw">end</span>
173:         <span class="ruby-keyword kw">end</span>
174:       <span class="ruby-keyword kw">end</span>
175:       <span class="ruby-identifier">full_messages</span>
176:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001214" class="method-detail">
        <a name="M001214"></a>

        <div class="method-heading">
          <a href="#M001214" class="method-signature">
          <span class="method-name">invalid?</span><span class="method-args">(attribute)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if the specified <tt>attribute</tt> has errors associated with
it.
</p>
<h4>Examples</h4>
<pre>
  my_resource = Disk.find(1)
  my_resource.errors.add('location', 'must be Main') unless my_resource.location == 'Main'
  my_resource.errors.on('location')
  # =&gt; 'must be Main!'

  my_resource.errors.invalid?('location')
  # =&gt; true
  my_resource.errors.invalid?('name')
  # =&gt; false
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001214-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001214-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/validations.rb, line 67</span>
67:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">invalid?</span>(<span class="ruby-identifier">attribute</span>)
68:       <span class="ruby-operator">!</span><span class="ruby-ivar">@errors</span>[<span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">to_s</span>].<span class="ruby-identifier">nil?</span>
69:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001224" class="method-detail">
        <a name="M001224"></a>

        <div class="method-heading">
          <span class="method-name">length</span><span class="method-args">()</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="Errors.html#M001222">size</a>
</p>
        </div>
      </div>

      <div id="method-M001215" class="method-detail">
        <a name="M001215"></a>

        <div class="method-heading">
          <a href="#M001215" class="method-signature">
          <span class="method-name">on</span><span class="method-args">(attribute)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A method to return the errors associated with <tt>attribute</tt>, which
returns nil, if no errors are associated with the specified
<tt>attribute</tt>, the error message if one error is associated with the
specified <tt>attribute</tt>, or an array of error messages if more than
one error is associated with the specified <tt>attribute</tt>.
</p>
<h4>Examples</h4>
<pre>
  my_person = Person.new(params[:person])
  my_person.errors.on('login')
  # =&gt; nil

  my_person.errors.add('login', 'can not be empty') if my_person.login == ''
  my_person.errors.on('login')
  # =&gt; 'can not be empty'

  my_person.errors.add('login', 'can not be longer than 10 characters') if my_person.login.length &gt; 10
  my_person.errors.on('login')
  # =&gt; ['can not be empty', 'can not be longer than 10 characters']
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001215-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001215-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/validations.rb, line 87</span>
87:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">on</span>(<span class="ruby-identifier">attribute</span>)
88:       <span class="ruby-identifier">errors</span> = <span class="ruby-ivar">@errors</span>[<span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">to_s</span>]
89:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">errors</span>.<span class="ruby-identifier">nil?</span>
90:       <span class="ruby-identifier">errors</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">errors</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">errors</span>
91:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001217" class="method-detail">
        <a name="M001217"></a>

        <div class="method-heading">
          <a href="#M001217" class="method-signature">
          <span class="method-name">on_base</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A method to return errors assigned to <tt>base</tt> object through <a
href="Errors.html#M001212">add_to_base</a>, which returns nil, if no errors
are associated with the specified <tt>attribute</tt>, the error message if
one error is associated with the specified <tt>attribute</tt>, or an array
of error messages if more than one error is associated with the specified
<tt>attribute</tt>.
</p>
<h4>Examples</h4>
<pre>
  my_account = Account.find(1)
  my_account.errors.on_base
  # =&gt; nil

  my_account.errors.add_to_base(&quot;This account is frozen&quot;)
  my_account.errors.on_base
  # =&gt; &quot;This account is frozen&quot;

  my_account.errors.add_to_base(&quot;This account has been closed&quot;)
  my_account.errors.on_base
  # =&gt; [&quot;This account is frozen&quot;, &quot;This account has been closed&quot;]
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001217-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001217-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/validations.rb, line 112</span>
112:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">on_base</span>
113:       <span class="ruby-identifier">on</span>(<span class="ruby-identifier">:base</span>)
114:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001222" class="method-detail">
        <a name="M001222"></a>

        <div class="method-heading">
          <a href="#M001222" class="method-signature">
          <span class="method-name">size</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the total number of errors added. Two errors added to the same
attribute will be counted as such with this as well.
</p>
<h4>Examples</h4>
<pre>
  my_person = Person.new(params[:person])
  my_person.errors.size
  # =&gt; 0

  my_person.errors.add('login', 'can not be empty') if my_person.login == ''
  my_person.errors.add('password', 'can not be empty') if my_person.password == ''
  my_person.error.size
  # =&gt; 2
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001222-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001222-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/validations.rb, line 195</span>
195:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">size</span>
196:       <span class="ruby-ivar">@errors</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-value">0</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">error_count</span>, <span class="ruby-identifier">attribute</span><span class="ruby-operator">|</span> <span class="ruby-identifier">error_count</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">size</span> }
197:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>